package com.example.lib_mvp.httpUtil;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;


import com.example.lib_mvp.base.mvp.HttpCallback;
import com.tjf.lib_network.HttpHelper;
import com.tjf.lib_network.OkSseClient;
import com.tjf.lib_network.SpSaveUtils;
import com.tjf.lib_network.httpHelper.CallBackUtil;
import com.tjf.lib_network.okhttp.OkhttpUtil;
import com.tjf.lib_network.okhttp.ThreadManager;
import com.tjf.lib_utils.EventBusUtils;
import com.tjf.lib_utils.GsonUtils;
import com.tjf.lib_utils.LogsUtils;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Response;
import okhttp3.sse.EventSource;
import okhttp3.sse.EventSourceListener;

public class HttpUtil extends BaseHttp {

    /**
     * 注册接口
     *
     * @param callBack
     */
    public static void getHdRegister(String phone, String code, String password, String pwd, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.LOGIN_REGISTER;
        HashMap<String, String> param = new HashMap<>();
        param.put("phone", phone);
        param.put("code", code);
        param.put("password", password);
        param.put("pwd", pwd);
        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }

    /**
     * 登录接口
     *
     * @param callBack
     */
    public static void getHdLogin(String phone, String code, String password, int type, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.LOGIN_LOGIN;
        HashMap<String, String> param = new HashMap<>();
        param.put("phone", phone);
        param.put("type", type + "");
        if (type == 1) {
            param.put("code", code);
        } else {
            param.put("password", password);
        }
        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }

    /**
     * 验证码接口
     *
     * @param callBack
     */
    public static void getHdLoginSms(String phone, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.LOGIN_SMS;
        HashMap<String, String> param = new HashMap<>();
        param.put("phone", phone);
        HttpHelper.getHttpHelper().okHttpGet(url, param, onCallBack(callBack));
    }

    /**
     * 获取聊天模型列表
     *
     * @param callBack
     */
    public static void getHdModelList(HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MODEL_LIST;
        HttpHelper.getHttpHelper().okHttpPost(url, onCallBack(callBack));
    }


    /**
     * 获取会话记录
     *
     * @param callBack
     */
    public static void getHdConversationList(HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.CONVERSATION_LIST;
        HttpHelper.getHttpHelper().okHttpPost(url, onCallBack(callBack));
    }

    /**
     * 删除会话记录
     *
     * @param callBack
     */
    public static void getHdConversationDelete(String conversation_id, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.CONVERSATION_DELETE;
        HashMap<String, Object> param = new HashMap<>();
        param.put("conversation_id", conversation_id);
        HttpHelper.getHttpHelper().okHttpPostJson(url, GsonUtils.toJson(param), onCallBack(callBack));
    }


    /**
     * 获取画图-风格列表
     *
     * @param callBack
     */
    public static void getHdDrawStyleList(HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.DRAW_STYLE_LIST;
        HttpHelper.getHttpHelper().okHttpPost(url, onCallBack(callBack));
    }

    /**
     * 获取AI画图
     *
     * @param callBack
     */
    public static void getHdDrawTxt2Img(Txt2ImgBean txt2ImgBean, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.DRAW_TXT2_IMG;
        HttpHelper.getHttpHelper().okHttpPostJson(url, GsonUtils.toJson(txt2ImgBean), onCallBack(callBack));
    }

    /**
     * 获取画图状态
     *
     * @param callBack
     */
    public static void getHdDrawStatus(String task_id, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.DRAW_STATUS;
        HashMap<String, Object> param = new HashMap<>();
        param.put("task_id", task_id);
        HttpHelper.getHttpHelper().okHttpPostJson(url, GsonUtils.toJson(param), onCallBack(callBack));
    }

    /**
     * 删除历史记录
     *
     * @param callBack
     */
    public static void getHdHistoryDelete(String id, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.HISTORY_DELETE;
        HashMap<String, Object> param = new HashMap<>();
        param.put("id", id);
        HttpHelper.getHttpHelper().okHttpPostJson(url, GsonUtils.toJson(param), onCallBack(callBack));
    }

    /**
     * 历史上记录
     *
     * @param callBack
     */
    public static void getHdHistoryList(String conversation_id, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.HISTORY_LIST;
        HashMap<String, Object> param = new HashMap<>();
        param.put("conversation_id", conversation_id);
        HttpHelper.getHttpHelper().okHttpPostJson(url, GsonUtils.toJson(param), onCallBack(callBack));
    }

    /**
     * 文件上传
     *
     * @param callBack
     */
    public static void getHdUploadFile(String filePath, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.UPLOAD_FILE;
        File file = new File(filePath);
        HttpHelper.getHttpHelper().okHttpUploadFile(url, file, "file", OkhttpUtil.FILE_TYPE_IMAGE, onCallBack(callBack));
    }

    /**
     * 知识库
     *
     * @param
     */
    public static void getHdKnowledgeChat(String question, String urlFile, String file_type, SseCallBack sseCallBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.KNOWLEDGE_CHAT;
        HashMap<String, Object> param = new HashMap<>();
        param.put("question", question);
        param.put("url", urlFile);
        param.put("file_type", file_type);
        HashMap<String, String> map = new HashMap<>();
        map.put("Content-type", "application/json");
        sse(url, GsonUtils.toJson(param), "", map, sseCallBack);
    }

    /**
     * 翻译
     *
     * @param callBack
     */
    public static void getHdTranslate(String text, String from, String to,
                                      int from_lang, int to_lang,
                                      int come_from,
                                      int type,

                                      HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.TRANSLATE_MULTIMODAL;
        HashMap<String, Object> param = new HashMap<>();
        param.put("text", text);
        param.put("from", from);
        param.put("to", to);
        param.put("from_lang", from_lang);
        param.put("to_lang", to_lang);

        param.put("come_from", come_from);
        param.put("type", type);

        HttpHelper.getHttpHelper().okHttpPostJson(url, GsonUtils.toJson(param), onCallBack(callBack));
    }

    /**
     * 翻译 语言选择
     *
     * @param callBack
     */
    public static void getHdTranslateDoc(HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.TRANSLATE_DOC;
        HttpHelper.getHttpHelper().okHttpPost(url, onCallBack(callBack));
    }
    /**
     * 翻译 语言选择 面对面
     *
     * @param callBack
     */
    public static void getHdTranslateDocx(HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.TRANSLATE_DOCX;
        HttpHelper.getHttpHelper().okHttpPost(url, onCallBack(callBack));
    }
    /**
     * 翻译 历史记录
     *
     * @param callBack
     */
    public static void getHdTranslateHistory(int page, int size, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.TRANSLATE_HISTORY;
        HashMap<String, String> param = new HashMap<>();
        param.put("page", page + "");
        param.put("size", size + "");
        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }

    /**
     * 翻译 -删除记录
     *
     * @param callBack
     */
    public static void getHdTranslateDelete(String id, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.TRANSLATE_DELETE;
        HashMap<String, String> param = new HashMap<>();
        param.put("id", id);
        HttpHelper.getHttpHelper().okHttpGet(url, param, onCallBack(callBack));
    }

    /**
     * 设备列表
     *
     * @param callBack
     */
    public static void getHdDeviceList(String type, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.DEVICE_LIST;
        HashMap<String, String> param = new HashMap<>();
        param.put("type", type);
        HttpHelper.getHttpHelper().okHttpGet(url, param, onCallBack(callBack));
    }


    /**
     * 我的设备
     *
     * @param callBack
     */
    public static void getHdDeviceMy(String uuid, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.DEVICE_MY;
        HashMap<String, String> param = new HashMap<>();
        param.put("uuid", uuid);
        HttpHelper.getHttpHelper().okHttpGet(url, param, onCallBack(callBack));
    }


    /**
     * 修改设备id
     *
     * @param callBack
     */
    public static void getHdDeviceUpdateUuid(String uuid, String id, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.DEVICE_UPDATE_UUID;
        HashMap<String, String> param = new HashMap<>();
        param.put("id", id);
        param.put("uuid", uuid);
        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }

    /**
     * 设备激活
     *
     * @param callBack
     */
    public static void getHdMyActivation(String order_id, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MY_ACTIVATION;
        HashMap<String, String> param = new HashMap<>();
        param.put("order_id", order_id);
        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }

    /**
     * 我的-用户基本信息
     *
     * @param callBack
     */
    public static void getHdMyInfo(HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MY_INFO;
        HttpHelper.getHttpHelper().okHttpGet(url, onCallBack(callBack));
    }

    /**
     * 退出登录
     *
     * @param callBack
     */
    public static void getHdMyLogout(String order_id, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MY_LOGOUT;
        HttpHelper.getHttpHelper().okHttpPost(url, onCallBack(callBack));
    }


    /**
     * 注销登录
     *
     * @param callBack
     */
    public static void getHdMyUnregister(HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MY_UNREGISTER;

        HttpHelper.getHttpHelper().okHttpPost(url, onCallBack(callBack));
    }

    /**
     * 修改密码
     *
     * @param callBack
     */
    public static void getHdMyUpdatePwd(String pwd, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MY_UPDATE_PWD;
        HashMap<String, String> param = new HashMap<>();
        param.put("pwd", pwd);
        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }

    /**
     * 修改名称
     *
     * @param callBack
     */
    public static void getHdMyUpdateName(String name, String avatarUrl, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MY_UPDATE_NAME;
        HashMap<String, String> param = new HashMap<>();
        param.put("name", name);
        param.put("avatar", avatarUrl);
        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }

    /**
     * 会议纪要-AI整理
     *
     * @param callBack
     */
    public static void getHdMeetingAi(String content, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MEETING_AI;
        HashMap<String, String> param = new HashMap<>();
        param.put("content", content);
        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }

    /**
     * 会议纪要-列表
     *
     * @param callBack
     */
    public static void getHdMeetingList(int page, int size, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MEETING_LIST;
        HashMap<String, String> param = new HashMap<>();
        param.put("page", page + "");
        param.put("size", size + "");
        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }


    /**
     * 会议纪要-AI添加
     *
     * @param callBack
     */
    public static void getHdMeetingAdd(String title, String content, String ai_content, String mp3_url, String duration, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MEETING_ADD;
        HashMap<String, String> param = new HashMap<>();
        param.put("title", title);
        param.put("content", content);
        param.put("ai_content", ai_content);
        param.put("mp3_url", mp3_url);
        param.put("duration", duration);
        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }


    /**
     * 会议纪要-删除
     *
     * @param callBack
     */
    public static void getHdMeetingDelete(String id, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MEETING_DELETE;
        HashMap<String, String> param = new HashMap<>();
        param.put("id", id);
        HttpHelper.getHttpHelper().okHttpGet(url, param, onCallBack(callBack));
    }


    /**
     * 课堂笔记-AI整理
     *
     * @param callBack
     */
    public static void getHdNoteAi(String content, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.NOTE_AI;
        HashMap<String, String> param = new HashMap<>();
        param.put("content", content);
        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }

    /**
     * 课堂笔记-列表
     *
     * @param callBack
     */
    public static void getHdNoteList(int page, int size, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.NOTE_LIST;
        HashMap<String, String> param = new HashMap<>();
        param.put("page", page + "");
        param.put("size", size + "");
        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }


    /**
     * 课堂笔记-AI添加
     *
     * @param callBack
     */
    public static void getHdNoteAdd(String title, String content, String ai_content, String mp3_url, String duration, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.NOTE_ADD;
        HashMap<String, String> param = new HashMap<>();
        param.put("title", title);
        param.put("content", content);
        param.put("ai_content", ai_content);
        param.put("mp3_url", mp3_url);
        param.put("duration", duration);

        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }


    /**
     * 课堂笔记-删除
     *
     * @param callBack
     */
    public static void getHdNoteDelete(String id, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.NOTE_DELETE;
        HashMap<String, String> param = new HashMap<>();
        param.put("id", id);
        HttpHelper.getHttpHelper().okHttpGet(url, param, onCallBack(callBack));
    }


    /**
     * 语音转文字-列表
     *
     * @param callBack
     */
    public static void getHdTransliterateList(int page, int size, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.TRANSLITERATE_LIST;
        HashMap<String, String> param = new HashMap<>();
        param.put("page", page + "");
        param.put("size", size + "");
        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }


    /**
     * 语音转文字-AI添加
     *
     * @param callBack
     */
    public static void getHdTransliterateAdd(String title, String content, String duration, String mp3_url, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.TRANSLITERATE_ADD;
        HashMap<String, String> param = new HashMap<>();
        param.put("title", title);
        param.put("content", content);
        param.put("mp3_url", mp3_url);
        param.put("duration", duration);
        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }


    /**
     * 语音转文字-删除
     *
     * @param callBack
     */
    public static void getHdTransliterateDelete(String id, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.TRANSLITERATE_DELETE;
        HashMap<String, String> param = new HashMap<>();
        param.put("id", id);
        HttpHelper.getHttpHelper().okHttpGet(url, param, onCallBack(callBack));
    }


    /**
     * 教程列表
     *
     * @param callBack
     */
    public static void getHdTutorialList(HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.CONFIG_TUTORIAL_LIST;

        HttpHelper.getHttpHelper().okHttpGet(url, onCallBack(callBack));
    }


    /**
     * 轮播图-列表
     *
     * @param callBack
     */
    public static void getHdCarouselList(HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.CAROUSEL_LIST;

        HttpHelper.getHttpHelper().okHttpGet(url, onCallBack(callBack));
    }

    /**
     * 用户协议
     *
     * @param callBack
     */
    public static void getHdAgreementList(HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.CONFIG_AGREEMENT;

        HttpHelper.getHttpHelper().okHttpGet(url, onCallBack(callBack));
    }


    /**
     * 用户协议-隐私协议
     *
     * @param callBack
     */
    public static void getHdPrivacyPolicyList(HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.CONFIG_PRIVACY_POLICY;
        HttpHelper.getHttpHelper().okHttpGet(url, onCallBack(callBack));
    }

    /**
     * 许可政策
     *
     * @param callBack
     */
    public static void getHdPermissionPolicyList(String id, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.CONFIG_PERMISSION_POLICY;

        HttpHelper.getHttpHelper().okHttpGet(url, onCallBack(callBack));
    }

    /**
     * 合作政策
     *
     * @param callBack
     */
    public static void getHdCooperatePolicy(HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.CONFIG_COOPERATE_POLICY;

        HttpHelper.getHttpHelper().okHttpGet(url, onCallBack(callBack));
    }


    /**
     * 关于我们
     *
     * @param callBack
     */
    public static void getHdCompany(HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.CONFIG_COMPANY;
        HttpHelper.getHttpHelper().okHttpGet(url, onCallBack(callBack));
    }

    /**
     * 一键登录
     *
     * @param callBack
     */
    public static void getHdOneLogin(String loginToken, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.LOGIN_ONE_LOGIN;
        HashMap<String, String> param = new HashMap<>();
        param.put("token", loginToken);
        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }


    /**
     * AI音乐-我的音乐列表
     *
     * @param callBack
     */
    public static void getHdMusicList(HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MUSIC_LIST;
        HttpHelper.getHttpHelper().okHttpPost(url, onCallBack(callBack));
    }

    /**
     * AI音乐-发现音乐
     *
     * @param callBack
     */
    public static void getHdMusicSquare(int page,HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MUSIC_SQUARE;
        HashMap<String, String> param = new HashMap<>();
        param.put("page", page + "");
        param.put("size", 10 + "");
        HttpHelper.getHttpHelper().okHttpPost(url,param, onCallBack(callBack));
    }

    /**
     * AI音乐-创建歌词流式
     *
     * @param
     */
    public static void getHdMusicCreate(String content, SseCallBack sseCallBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MUSIC_CREATE;
        HashMap<String, String> map = new HashMap<>();
        map.put("Content-type", "application/json");
        HashMap<String, String> param = new HashMap<>();
        param.put("content", content);
        String jsonStr = GsonUtils.toJson(param);
        sse(url, jsonStr, "", map, sseCallBack);
    }

    /**
     * AI音乐-创建歌词
     *
     * @param callBack
     */
    public static void getHdMusicCreateLyric(String content, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MUSIC_CREATE_LYRIC;
        HashMap<String, String> param = new HashMap<>();
        param.put("content", content);
        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }

    /**
     * AI音乐 状态
     *
     * @param callBack
     */
    public static void getHdMusicStatus(String task_id, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MUSIC_STATUS;
        HashMap<String, String> param = new HashMap<>();
        param.put("task_id", task_id);
        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }

    /**
     * AI音乐作曲
     *
     * @param callBack
     */
    public static void getHdMusicCompose(String lyric, String tags, String song, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MUSIC_COMPOSE;
        HashMap<String, String> param = new HashMap<>();
        param.put("lyric", lyric);
        param.put("tags", tags);
        param.put("song", song);
        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }

    /**
     * AI音乐-发布
     *
     * @param callBack
     */
    public static void getHdMusicRelease(String id, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MUSIC_RELEASE;
        HashMap<String, String> param = new HashMap<>();
        param.put("id", id);
        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }

    /**
     * AI音乐-风格
     *
     * @param callBack
     */
    public static void getHdMusicTag(HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MUSIC_TAG;
        HttpHelper.getHttpHelper().okHttpPost(url, onCallBack(callBack));
    }

    /**
     * AI音乐-睡眠音乐
     *
     * @param callBack
     */
    public static void getHdMusicSleep(int page,HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MUSIC_SLEEP;
        HashMap<String, String> param = new HashMap<>();
        param.put("page", page + "");
        param.put("size", 10 + "");
        HttpHelper.getHttpHelper().okHttpPost(url,param, onCallBack(callBack));
    }


    /**
     * AI音乐-睡眠音乐
     *
     * @param callBack
     */
    public static void getHdMusicBanner(HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.MUSIC_BANNER;
        HttpHelper.getHttpHelper().okHttpGet(url, onCallBack(callBack));
    }

    /**
     * 一句话语音转文字
     *
     * @param callBack
     */
    public static void getHdVoiceToTextConversion(String lanId, String filePath, HttpCallback<String> callBack) {
        String url = "http://150.158.100.130:9399/dotcasr?lanid=" + lanId;
        HashMap<String, String> param = new HashMap<>();
        param.put("token", SpSaveUtils.getToken());
        param.put("userid", SpSaveUtils.getUserId());
        File file = new File(filePath);
        HttpHelper.getHttpHelper().okHttpUploadFile(url, file, "file", OkhttpUtil.FILE_TYPE_AUDIO, param, onCallBack(callBack));
    }

    /**
     * 文字转语音合成
     *
     * @param callBack
     */
    public static void getHdTextToSpeechSynthesis(String lanId, String urlFilePath, HttpCallback<String> callBack) {
//        String url ="http://150.158.100.130:9399/dotcmultispksplit2?lanid="+lanId;
//        HashMap<String ,String> param=new HashMap<>();
//        param.put("token", SpSaveUtils.getToken());
//        param.put("userid",SpSaveUtils.getUserId());
//        param.put("asr","1");
//        param.put("mp","0");

        String url = "http://region-9.autodl.pro:35044/s2tt";

        // 读取本地音频文件并进行 Base64 编码


        HashMap<String, String> param = new HashMap<>();
        param.put("path", urlFilePath);

        HttpHelper.getHttpHelper().okHttpPostJson(url, GsonUtils.toJson(param), onCallBack(callBack));
//        HttpHelper.getHttpHelper().okHttpUploadFile(url, file, "input_audio",
//                OkhttpUtil.FILE_TYPE_AUDIO, param, onCallBack(callBack));
    }

    /**
     * 语音转文字
     *
     * @param callBack
     */
    public static void getHdSpeechToTextAsr(String language, String urlFilePath) {
        String url = "http://region-9.autodl.pro:35044/call/asr";
        HashMap<String, List<Object>> param = new HashMap<>();
        List<Object> data = new ArrayList<>();
        HashMap<String, String> path = new HashMap<>();
        path.put("path", urlFilePath);
        data.add(path);
        data.add(language);
        param.put("data", data);
        HttpHelper.getHttpHelper().okHttpPostJson(url, GsonUtils.toJson(param), new CallBackUtil.CallBackString() {
            @Override
            public void onFailure(Call call, Exception e) {

            }

            @Override
            public void onResponse(Call call, String response) {
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    String event_id = jsonObject.getString("event_id");
                    getHdAsrResult(event_id);
                } catch (JSONException e) {
                    throw new RuntimeException(e);
                }
            }
        });
    }


    /**
     * 语音转文字
     *
     * @param callBack
     */
    public static void getHdAsrResult(String event_id) {
        String url = "http://region-9.autodl.pro:35044/call/asr/" + event_id;
        OkSseClient okSseClient = new OkSseClient();
        okSseClient.getSmTl4EventId(url, new EventSourceListener() {
            @Override
            public void onEvent(@NonNull EventSource eventSource, @Nullable String id,
                                @Nullable String type, @NonNull String data) {
                super.onEvent(eventSource, id, type, data);
                LogsUtils.i("结果==" + data);
                EventBusUtils.sendEvent("语音转文字", data);
            }
        });
    }


    public static void getHdChatFrom(String to_lang, String from_lang, String filePath, SseCallBack sseCallBack) {
        String url = HttpUrl.BASE_URL + "speech/asr";
        HashMap<String, String> param = new HashMap<>();
        param.put("to_lang", to_lang);
        param.put("form_lang", from_lang);
        LogsUtils.e("getHdChatFrom==开始请求转文字");
        OkSseClient okSseClient = new OkSseClient();
        okSseClient.getChatAiFrom(url, filePath, param, new EventSourceListener() {
            @Override
            public void onClosed(@NonNull EventSource eventSource) {
                super.onClosed(eventSource);
            }

            @Override
            public void onEvent(@NonNull EventSource eventSource, @Nullable String id, @Nullable String type, @NonNull String data) {
                super.onEvent(eventSource, id, type, data);
                setAiChatCallBack(url, sseCallBack, "100", 0, data, "[DONE]".equals(data));

            }

            @Override
            public void onFailure(@NonNull EventSource eventSource, @Nullable Throwable t, @Nullable Response response) {
                super.onFailure(eventSource, t, response);
            }

            @Override
            public void onOpen(@NonNull EventSource eventSource, @NonNull Response response) {
                super.onOpen(eventSource, response);
            }
        });

    }


    /**
     * 一句话语音转文字
     *
     * @param callBack
     */
    public static void getHdTts(String content, String dst, int lang, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.TRANSLATE_TTS;
        HashMap<String, String> param = new HashMap<>();
        param.put("content", content);
        param.put("dst", dst);
        param.put("lang", lang+"");
        HttpHelper.getHttpHelper().okHttpPost(url, param, onCallBack(callBack));
    }

    /**
     * 一句话语音转文字
     *
     * @param callBack
     */
    public static void getHdAsr(String dst, int lang, String filePath, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.TRANSLATE_ASR;
        HashMap<String, String> param = new HashMap<>();
        param.put("dst", dst);
        param.put("lang", lang+"");
        File file = new File(filePath);
        HttpHelper.getHttpHelper().okHttpUploadFile(url, file, "file", OkhttpUtil.FILE_TYPE_AUDIO, param, onCallBack(callBack));
    }
    /**
     * 一句话语音转文字
     *
     * @param callBack
     */
    public static void getHdUpLoadAsr(String dst, int lang, String filePath, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.UPLOAD_ASR;
        HashMap<String, String> param = new HashMap<>();
        param.put("dst", dst);
        param.put("lang", lang+"");
        File file = new File(filePath);
        HttpHelper.getHttpHelper().okHttpUploadFile(url, file, "file", OkhttpUtil.FILE_TYPE_AUDIO, param, onCallBack(callBack));
    }

    /**
     * 获取音频转文字的记录
     *
     * @param callBack
     */
    public static void getHdUpLoadAsrStatus(String task_id, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.TRANSLATE_CONTENT;
        HashMap<String, Object> param = new HashMap<>();
        param.put("task_id", task_id);
        HttpHelper.getHttpHelper().okHttpPostJson(url, GsonUtils.toJson(param), onCallBack(callBack));
    }
    public static void getHdTransliterateAi(String content, HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.TRANSLITERATE_AI;
        HashMap<String, String> param = new HashMap<>();
        param.put("content", content);
        HttpHelper.getHttpHelper().okHttpPost(url,  param, onCallBack(callBack));
    }

    public static void getHdTranslateTDox(  HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.TRANSLATE_TDOCX;
        HttpHelper.getHttpHelper().okHttpPost(url, onCallBack(callBack));
    }

    /**
     * ai聊天-历史记录
     *
     * @param callBack
     */
    public static void getHdAiHistoryList(int page, int pageSize,HttpCallback<String> callBack) {
        String url = HttpUrl.BASE_URL + HttpUrl.AIHISTORY_LIST;
        HashMap<String, String> param = new HashMap<>();
        param.put("page", page + "");
        param.put("size", pageSize + "");
        HttpHelper.getHttpHelper().okHttpPost(url,param, onCallBack(callBack));
    }


    /**
     * 获取 ai模型对话的数据
     *
     * @param conversation_id
     * @param sseCallBack
     */
    public static void getHdChatAi(String conversation_id, String question, SseCallBack sseCallBack) {
        String url = HttpUrl.BASE_URL + "chat/gpt";

        HashMap<String, String> map = new HashMap<>();
        map.put("Content-type", "application/json");

        Map<String, Object> param = new HashMap<>();
        param.put("question", question);
        param.put("type", 1);
        param.put("model_id", 5);
        param.put("conversation_id", conversation_id);
        String jsonStr = GsonUtils.toJson(param);
        LogsUtils.i("接口参数==", jsonStr);

        sse(url, jsonStr, "5", map, sseCallBack);
    }

    /**
     * 获取 ai模型对话的数据
     */
    public static void getHdChatAi(SendAiChatBean sendAiChatBean, SseCallBack sseCallBack) {
        String url = HttpUrl.BASE_URL + "chat/gpt";

        HashMap<String, String> map = new HashMap<>();
        map.put("Content-type", "application/json");

        Map<String, Object> param = new HashMap<>();
        param.put("question", sendAiChatBean.getQuestion());
        param.put("type", sendAiChatBean.getType());
        param.put("model_id", sendAiChatBean.getModel_id());
        param.put("conversation_id", sendAiChatBean.getConversation_id());
        if (sendAiChatBean.getType().equals("2")) {
            param.put("multimode_id", sendAiChatBean.getMultimode_id());
        }
        String jsonStr = GsonUtils.toJson(param);
        LogsUtils.i("接口参数==", jsonStr);
        sse(url, jsonStr, sendAiChatBean.getModel_id(), map, sseCallBack);
    }

    public static void sse(String url, String jsonStr, String model_Id, HashMap<String, String> map, SseCallBack sseCallBack) {
        OkSseClient.getChatAi(url, jsonStr, map, new EventSourceListener() {
            @Override
            public void onClosed(@NonNull EventSource eventSource) {
                super.onClosed(eventSource);
                setAiChatCallBack(url, sseCallBack, model_Id, 1, "", true);
            }

            @Override
            public void onEvent(@NonNull EventSource eventSource, @Nullable String id, @Nullable String type, @NonNull String data) {
                super.onEvent(eventSource, id, type, data);
//                LogsUtils.i("onEvent==", data);
                setAiChatCallBack(url, sseCallBack, model_Id, 0, data, "[DONE]".equals(data));
            }

            @Override
            public void onFailure(@NonNull EventSource eventSource, @Nullable Throwable t, @Nullable Response response) {
                super.onFailure(eventSource, t, response);
                LogsUtils.i("onFailure==", GsonUtils.toJson(response.body()));
                setAiChatCallBack(url, sseCallBack, model_Id, 2, "异常", true);
            }

            @Override
            public void onOpen(@NonNull EventSource eventSource, @NonNull Response response) {
                super.onOpen(eventSource, response);
//                sseCallBack.onSseCallBack(0, "", false);
            }
        });
    }

    public static void setAiChatCallBack(String url, SseCallBack callback, String model_Id, int status, String result, Boolean isLast) {
        ThreadManager.mMainHandler.post(new Runnable() {
            @Override
            public void run() {
                callback.onSseCallBack(url, model_Id, status, result, isLast);
            }
        });
    }

    public interface SseCallBack {
        void onSseCallBack(String url, String model_Id, int status, String result, Boolean isLast);
    }
}
